#! /usr/bin/env python3

import sys

# fg: \033[38;5;?m
# bg: \033[48;5;?m
def xterm_256color(is_fg):
    if is_fg:
        fgbg = 38
    else:
        fgbg = 48
    for i in range(0, 256):
        print(f"\033[{fgbg};5;{i}m {i:3} \033[0m", end="")
        if i < 16:
            if (i + 1) % 8 == 0:
                print()
        else:
            if (i + 3) % 6 == 0:
                print()

if __name__ == "__main__":
    argnum = len(sys.argv)
    if argnum == 1:
        xterm_256color(True)
    else:
        xterm_256color(False)
